<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <input id="approverId" name="approverId" th:value="${approver.id}" type="hidden">
    <input id="roleId" name="roleId" th:value="${roleId}" type="hidden"><!-- 待办人员角色 -->
    <input id="tableId" name="tableId" th:value="${approver.tableId}" type="hidden">
    <input id="projectType" name="projectType" th:value="${pefassproject.projectType}" type="hidden">
    <input id="approverCode" name="approverCode" th:value="${approver.approverCode}" type="hidden">
    <form class="form-horizontal m" id="form-appeal-add">
        <input id="" name="tableId" th:value="${approver.tableId}" type="hidden">
        <input id="" name="approverId" th:value="${approver.id}" type="hidden">
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red;">*</span>方案名称：</label>
                    <div class="col-sm-6">
                        <input class="form-control" id="projectName" name="projectName"
                               readonly th:field="*{pefassproject.projectName}" type="text">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>考核对象：</label>
                    <div class="col-sm-6">
                        <input class="form-control" id="asseObject" name="asseObject"
                               readonly th:field="*{pefctasstable.memberName}" type="text">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>申诉时间：</label>
                    <div class="col-sm-6">
                        <input class="time-input form-control" id="appealDate" name="appealDate" required type="text">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>申诉原因：</label>
                    <div class="col-sm-6">
                        <textarea class="form-control" id="appealResult" name="appealResult" required
                                  type="text"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <div class="btn-group-sm" id="toolbar">
        <a class="btn btn-success" onclick="doDefendIndex()">
            <i class="fa fa-cogs"></i> 维护指标
        </a>
        <!-- <a class="btn btn-success" onclick="doRemoveIndex()">
             <i class="fa fa-trash"></i> 删除
         </a>-->
        <a class="btn btn-success" onclick="doSubmitAppeal()">
            <i class="fa fa-check"></i> 提交
        </a>
        <!--<a class="btn btn-success" onclick="doCloseAppeal" >
            <i class="fa fa-close"></i> 关闭
        </a>-->
    </div>
    <hr style="border:0.3px solid #6b8595;"/>
    <div class="col-sm-12 select-table table-striped" id="appealDiv" style="display:none;">
        <table data-mobile-responsive="true" id="bootstrap-table"></table>
    </div>
    <div th:include="include::footer"></div>
    <script th:src="@{/ajax/libs//datapicker/bootstrap-datetimepicker.min.js}"></script>
    <script charset="gb2312" th:src="@{/js/rule.js}" type="text/javascript"></script>
    <script type="text/javascript">
        var prefix = ctx + "zzjx/appealTab"
        $("#form-appeal-add").validate({
            onkeyup: false,
            rules: {
                appealDate: {
                    required: true,
                },
                appealResult: {
                    required: true,
                },
            },
            focusCleanup: true
        });

        function doDefendIndex() {
            var approverId = $("#approverId").val();
            var tableId = $("#tableId").val();
            var projectType = $("#projectType").val();
            var approverCode = $("#approverCode").val();
            debugger
            $.modal.loading("正在加载数据，请稍后...");
            var url = ctx + "zzjx/appealTab/toAppealIndex?tableId=" + tableId + "&approverId=" + approverId + "&projectType=" + projectType + "&approverCode=" + approverCode;
            var _url = $.common.isEmpty(url) ? "/404.html" : url;
            var _height = ($(window).height() - 50);
            layer.open({
                type: 2,
                maxmin: true,
                shade: 0.3,
                title: '维护指标',
                fix: false,
                area: [1009 + 'px', _height + 'px'],
                content: _url,
                shadeClose: false,
                btn: ['<i class="fa fa-check"></i> 确定', '<i class="fa fa-close"></i> 关闭'],
                cancel: function () {
                    return true;
                },
                yes: function (index, layero) {
                    var obj = [];
                    var body = layer.getChildFrame('body', index);//建立父子联系【核心】
                    var iframeWin = window[layero.find('iframe')[0]['name']];//【核心】
                    var cols = iframeWin.cols;
                    var row = iframeWin.$("#tableIndex").bootstrapTable('getSelections');
                    if (row.length < 1) {
                        $.modal.alertError("请选择一条数据!");
                        return false;
                    }
                    for (let i = 0; i < row.length; i++) {
                        obj.push(row[i]);
                    }
                    if (obj.length > 0) {
                        $("#bootstrap-table").bootstrapTable('destroy').bootstrapTable({
                            columns: cols,
                            data: obj,
                            uniqueId: "id",
                            search: false,
                            showSearch: false,
                            showRefresh: false,
                            showToggle: false,
                            showColumns: false,
                            showExport: false,                     //是否显示导出
                            exportDataType: "basic",              //basic', 'all', 'selected'.
                            height: 600,
                            pagination: false,
                            modalName: "考核指标",
                            onDblClickRow: function (row) {
                                console.log("click:" + JSON.stringify(row))
                            }
                        });
                    }
                    $("#appealDiv").css("display", "block");
                    $('table input').attr('disabled', 'disabled');
                    $('table textarea').attr('disabled', 'disabled');
                    $('table select').attr('disabled', 'disabled');
                    layer.close(index);
                }
            });
            $.modal.closeLoading();
        }

        function doSubmitAppeal() {
            var flag = true;
            var data = $("#form-appeal-add").serializeArray();
            var selects = [];
            var appealRels = [];
            var tableId = $("#tableId").val();
            $.ajax({
                url: ctx + "zzjx/appealTab/getAppealRels"
                , data: {"tableId": tableId}
                , type: "GET"
                , async: false
                , success: function (result) {
                    if (result != null && result instanceof Array) {
                        for (var i = 0; i < result.length; i++) {
                            appealRels.push(result[i].pefprojeindicator);
                        }
                    }
                    console.log(result);
                }, error: function () {
                    $.modal.alertError("操作失败！");
                }
            })
            debugger
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            if (rows instanceof Array && appealRels instanceof Array) {
                for (var i = 0; i < appealRels.length; i++) {
                    $("#bootstrap-table [data-uniqueid=" + appealRels[i] + "]").css("background", "red");
                    for (var j = 0; j < rows.length; j++) {
                        if (appealRels[i] == rows[j].id) {
                            flag = false;
                        }
                    }
                }
            }
            if ($.validate.form()) {
                if (flag) {
                    if (rows != null && rows.length > 0 && rows instanceof Array) {
                        for (var i = 0; i < rows.length; i++) {
                            selects.push(rows[i].id);
                        }
                        data.push({"name": "ids", "value": selects});
                        $.operate.save(ctx + "zzjx/appealTab/addAppeal", data);
                    } else {
                        $.modal.alertWarning("暂无申诉指标进行申诉!");
                    }
                } else {
                    $.modal.alertWarning("有指标已申诉请勿重复申诉!");
                }
            }
        }
    </script>
</body>
</html>
